<template>
	<!-- 待缴款明细 -->
	<view class="dqjmx">
		<view class="title">
			<text>待清缴明细</text>
		</view>
		<view class="con">
			<view class="sm">说明：从微信绑定的银行卡扣缴税（费）款</view>
			<view class="table">
				<uni-table border stripe emptyText="暂无更多数据">
					<!-- 表头行 -->
					<uni-tr>
						<uni-th align="center" width="350rpx">电子税票号码</uni-th>
						<uni-th align="center" width="200rpx">应缴金额</uni-th>
						<uni-th align="center" width="150rpx">操作</uni-th>
					</uni-tr>
					<!-- 表格数据行 -->
					<uni-tr v-for="(item,index) in dqjmxLists" :key="index">
						<uni-td align="center">{{item.dzsphm}}</uni-td>
						<uni-td align="center">{{item.yjse}}</uni-td>
						<uni-td align="center">
							<view @click="goQrjf(JSON.stringify(item))">立即支付</view>
						</uni-td>
					</uni-tr>
				</uni-table>
			</view>
			<view class="btn">
				<button type="primary" size="mini" @click="jsjk">解锁税款</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		generateDzsphmYst
	} from "@/utils/common-api.js"
	export default {
		data() {
			return {
				dqjmxData: {
					djxh: "",
					sbId: "",
				},
				dqjmxLists: []
			}
		},
		async onShow() {
			// 查询缴款明细信息
			this.dqjmxLists = []
			this.dqjmxData = JSON.parse(uni.getStorageSync("dqjData"));
			let lists = await generateDzsphmYst({
				...this.dqjmxData
			})
			if (lists.head.errorCode == "0" && lists.body) {
				this.dqjmxLists = lists.body.jkxxGridlb
				console.log(this.dqjmxLists)
				if (this.dqjmxLists && this.dqjmxLists.length == 1) {
					this.goQrjf(JSON.stringify(this.dqjmxLists[0]))
				}
				console.log(lists.body.jkxxGridlb)
				if (!lists.body.jkxxGridlb || lists.body.jkxxGridlb.length == 0) {
					uni.showModal({
						title: '提示',
						content: '未获取到缴款信息，是否进行解锁税款？',
						confirmColor: '#007aff', //确定字体颜色
						buttonText: '确定',
						success: (res) => {
							if (res.confirm) {
								this.jsjk()
							} else {

							}
						}
					});
				}
			} else if (lists.head.errorCode == "99015") {
				uni.showModal({
					title: '提示',
					content: '该申报应征数量超过限额，暂不支持线上清缴，请到前台清缴',
					confirmColor: '#000000', //确定字体颜色
					showCancel: false, //没有取消按钮的弹框 
					buttonText: '确定',
					success: function(res) {
						if (res.confirm) {
							uni.navigateBack();
						}
					}
				});
			} else if (lists.head.errorCode == "888888") {
				uni.showModal({
					title: '提示',
					content: '滞纳金超过本金，不允许征收，请联系税务机关对滞纳金进行核销处理后，再操作！',
					confirmColor: '#000000', //确定字体颜色
					showCancel: false, //没有取消按钮的弹框 
					buttonText: '确定',
					success: (res) => {
						if (res.confirm) {
							this.$commonCzwjs.goPage({
								url: "/pages/sfqj/dqj"
							})
						}
					}
				})
				return
			} else if (lists.head.errorCode != "0") {
				uni.showToast({
					title: '数据请求失败',
					icon: 'error',
					duration: 3000
				})
			}
		},
		methods: {
			// 立即支付
			goQrjf(item) {
				item = JSON.parse(item)
				// 标志已缴款明细（用于判断是否支付）
				let lists = []
				this.dqjmxLists.map(val => {
					if (val.dzsphm == item.dzsphm) {
						val.jkztbz = true
					} else {
						val.jkztbz = false
					}
					lists.push({
						jkztbz: val.jkztbz,
						dzsphm: val.dzsphm,
						swjgDm: val.swjgDm,
						shxydm: val.shxydm,
						yjse: val.yjse
					})
				})
				console.log(JSON.stringify(lists))
				// 当前缴款明细数据（用于缴款状态查询）
				let dqjk = {
					dzsphm: item.dzsphm,
					skssswjgDm: item.swjgDm
				}
				// uni.redirectTo({
				// 	url: "/pages/sfqj/qjcg?data=" + JSON.stringify(lists)+"&dqjk="+JSON.stringify(dqjk)
				// })
				var xcxjkUrl = ""
				let sucUrl = ""
				let failUrl = ""
				if (process.env.ENV_TYPE == "test" || process.env.ENV_TYPE == "dev") {
					// 测试环境
					sucUrl =
						encodeURIComponent(
							"https://etaxtest.guangdong.chinatax.gov.cn/dzswjYst-czw/#/pages/sfqj/qjcg?data=" +
							JSON.stringify(lists))
					failUrl = encodeURIComponent(
						"https://etaxtest.guangdong.chinatax.gov.cn/dzswjYst-czw/#/pages/sfqj/qjsb")

				} else {
					//生产环境
					sucUrl =
						encodeURIComponent(
							"https://etax.guangdong.chinatax.gov.cn/dzswjYst-czw/#/pages/sfqj/qjcg?data=" +
							JSON.stringify(lists))
					failUrl = encodeURIComponent(
						"https://etax.guangdong.chinatax.gov.cn/dzswjYst-czw/#/pages/sfqj/qjsb")
				}
				xcxjkUrl = '/yssdishui/pages/pay/pay?outerLevyNo=' + item.dzsphm +
					'&taxOrgCode=' + item.swjgDm + '&busiType=tips&taxType=css&pay_channel=1&taxPayCode=' +
					item.shxydm + '&ywlx=ccs&sucUrl=' + sucUrl +
					'&failUrl=' + failUrl;
				console.log(xcxjkUrl)
				wx.miniProgram.reLaunch({
					url: xcxjkUrl
				})
			},
			// 解锁缴款 
			jsjk() {
				this.$commonCzwjs.goPage({
					url: "/pages/sfqj/jsjk"
				})
			}
		}
	}
</script>

<style>
	.title {
		width: 100%;
		height: 80rpx;
		background: #3171d5;
		text-align: center;
		line-height: 80rpx;
		color: white;
	}

	.sm {
		font-size: 24rpx;
		padding: 20rpx;
		color: #66666699;
	}

	.con {
		padding: 20rpx;
		background: #ffffff;
	}

	.uni-table .uni-table-th,
	.uni-table .uni-table-td {
		font-size: 24rpx;
		color: black;
	}

	.uni-table .uni-table-td:last-child {
		color: #4b4bff;
	}

	.btn {
		text-align: center;
		margin-top: 80rpx;
	}

	.btn uni-button {
		width: 590rpx;
		background-color: #3171d5;
		height: 70rpx;
		line-height: 70rpx;
	}

	/* #ifdef MP-WEIXIN */
	.btn button {
		width: 590rpx;
		background-color: #3171d5;
	}

	/* #endif */
</style>